<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <title>drpy小工具-{{ver}}</title>
    <meta name="description" content="particles.js is a lightweight JavaScript library for creating particles.">
    <meta name="author" content="道长"/>
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" media="screen" href="/static/css/admin.css">
    <link rel="icon" href="/static/img/logo.png" type="image/x-icon">
    <script src="/static/js/jquery.min.js"></script>
    <script src="/static/js/common.js"></script>
    <script src="/static/js/grey.js"></script>
    <link rel="stylesheet" href="/static/plugin/layui/css/layui.css">
    <script src="/static/plugin/layui/layui.js"></script>
    <script src="/static/js/pinyin-pro.js"></script>
    <script src="/static/js/tools.js"></script>

    <style>
        body {
            background-color: #ffffff;
        }

        .long_text {
            width: 100%;
            height: 300px;
            overflow-x: scroll;
            overflow-y: scroll;
        }
        .hide{
            display: none;
        }

    </style>
</head>
<body>
<script type="text/javascript">
    function init() {
        var dest = document.getElementById("source");
        dest.addEventListener("dragover", function (ev) {
            ev.stopPropagation();
            ev.preventDefault();
        }, false);

        dest.addEventListener("dragend", function (ev) {
            ev.stopPropagation();
            ev.preventDefault();
        }, false);

        dest.addEventListener("drop", function (ev) {
            ev.stopPropagation();
            ev.preventDefault();

            var file = ev.dataTransfer.files[0];
            var reader = new FileReader();

            if (file.type.substr(0, 4) != "text") {
                dest.innerHTML = "暂不支持此类文件的预览";
                dest.style.background = "white";
            } else if (file.type.substr(0, 4) == "text") {

                reader.readAsText(file);
                reader.onload = function (f) {
                    dest.innerHTML = "<pre>" + this.result + "</pre>";
                    dest.style.background = "white";
                }
            } else {
                dest.innerHTML = "暂不支持此类文件的预览";
                dest.style.background = "white";
            }
        }, false);
    }

    //设置页面属性，不执行默认处理（拒绝被拖放）
    document.ondragover = function (e) {
        e.preventDefault();
    }
    ;
    document.ondrop = function (e) {
        e.preventDefault();
    }

    window.onload = init;
</script>
<script type="text/javascript">
    function dl() {
        const data = document.getElementById("res").innerHTML.replace(/<br>/g, '\n');
        if (data.indexOf("EXTM3U") != -1) {
            var tt = "m3u"
        } else {
            var tt = "txt"
        }
        const blob = new Blob([data], {
            type: "text/plain"
        })
        const a = document.createElement("a")
        a.href = URL.createObjectURL(blob)
        a.download = "yourtv." + tt
        a.click()
        URL.revokeObjectURL(a.href)
        a.remove();
    }

    function copyText() {
        var text = document.getElementById("res").innerHTML;
        var input = document.createElement('textarea')
        input.innerHTML = text.replace(/<br>/g, "\n")
        input.setAttribute('readonly', 'readonly')
        document.body.appendChild(input)
        input.select();
        //选中文本
        document.execCommand("copy");
        document.body.removeChild(input);
        layer.msg('复制成功');
    }
</script>
<script>
    function readSingleFile(e) {
        var file = e.target.files[0];
        if (!file) {
            return;
        }
        var reader = new FileReader();
        reader.onload = function (e) {
            var contents = e.target.result;
            displayContents(contents);
        }
        ;
        reader.readAsText(file);
    }

    function displayContents(contents) {
        var element = document.getElementById('source');
        element.textContent = contents;
    }

    window.onload = function () {
        document.getElementById('file-input').addEventListener('change', readSingleFile, false);
    }
</script>

<div class="layui-form layuimini-form layuimini-container layui-form-pane container" lay-filter="scripts">
    <div class="layui-tab">
        <ul class="layui-tab-title">
            <li class="layui-this">直播转换工具</li>
            <li>更多</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <input type="file" id="file-input" class="layui-hide"/>
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
                    <legend>直播类文本文件上传(txt|m3u8|m3u)文件</legend>
                    <legend id="file_info"></legend>
                </fieldset>

                <div class="layui-btn-container">
                    <button type="button" class="layui-btn" id="file_select"><i class="layui-icon"></i>上传文件
                    </button>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label" for="action">超级直播格式</label>
                    <div class="layui-input-block">
                        <select id="action" name="action" lay-filter="action">
<!--                            <option value=""></option>-->
                            <option>112114-muziling</option>
                            <option>112114-yuanban</option>
                            <option>tvming-yuanban</option>
                            <option>cntv-yuanban</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <div class="layui-input-block">
                        <label class="layui-form-label required" for="source">文本区域</label>
                        <textarea id="source" name="source" class="layui-textarea"
                                  placeholder="请粘贴文本内容"
                                  rows='16' cols='86'></textarea>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button type="button" class="layui-btn layui-btn-normal" onclick="trans()">超级直播</button>
                    <button type="button" class="layui-btn layui-btn-normal" onclick="tran2m3u()">m3u格式</button>
                    <button type="button" class="layui-btn layui-btn-normal" onclick="tran2m3ugroup()">m3u分组</button>
                    <button type="button" class="layui-btn layui-btn-normal" onclick="m3u2txt()">m3u2txt</button>
                </div>
                <hr/>
                <div class="layui-form-item">
                    <button class="layui-btn hide" id="copytext" onclick="copyText()">一键复制</button>
                    <button class="layui-btn hide" id="downtext" onclick="dl()">一键下载</button>
                </div>

                <div>
                    <p id="res" name="res" class="long_text"></p>
                </div>

            </div>

            <div class="layui-tab-item">
                <h3>更多功能开发中...</h3>
                <hr/>
                <h3>下方是推荐链接</h3>
                <p class="layui-elem-quote"><a href="https://guihet.com/tvlistconvert.html" target="_blank">黑鸟博客转换工具</a></p>
                <p class="layui-elem-quote"><a href="https://wwi.lanzoup.com/i3CCw1fxlxla" target="_blank">IPTV Checker</a></p>
                <p class="layui-elem-quote"><a href="https://wwi.lanzoup.com/i3GgP1fxqdpe" target="_blank">安卓派大星直播</a></p>
                <p class="layui-elem-quote"><a href="https://epg.112114.xyz/" target="_blank">EPG小工具</a></p>
                <p class="layui-elem-quote"><a href="http://epg.51zmt.top:8000/" target="_blank">EPG节目信息</a></p>

            </div>
        </div>
    </div>

</div>

<script>
    layui.use(['upload', 'element', 'layer'], function () {
        var $ = layui.jquery
            , upload = layui.upload
            , element = layui.element
            , layer = layui.layer;

        $('#file_select').click(function () {
            $('#file-input').click();
        });

        $('#file-input').change(function () {
            //获取选择的文件信息
            let file = this.files[0];
            //执行上传操作
            if (file) {
                console.log(file);
                $('#file_info').text(`文件名:${file.name},体积:${(file.size / 1024).toFixed(2)}kb`);
            } else {
                $('#file_info').text('未选择文件');
            }
        });
    });
</script>

</body>

</html>